//package com.free.fs.core.fsadmin;
//
//import cn.dev33.satoken.stp.StpUtil;
//import com.free.fs.common.constant.CommonConstant;
//import com.free.fs.common.domain.FileBo;
//import com.free.fs.common.domain.Result;
//import com.free.fs.common.exception.BusinessException;
//import com.free.fs.common.storage.IFileStorage;
//import com.free.fs.common.storage.IFileStorageProvider;
//import com.free.fs.core.domain.FileInfo;
//import com.free.fs.core.domain.dto.UpdateFileNameDTO;
//import com.free.fs.core.mapper.FileMapper;
//import com.free.fs.core.service.FileService;
//import com.free.fs.core.service.impl.FileServiceImpl;
//import org.junit.jupiter.api.AfterEach;
//import org.junit.jupiter.api.Assertions;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//import org.mockito.InjectMocks;
//import org.mockito.Mock;
//import org.mockito.MockedStatic;
//import org.mockito.MockitoAnnotations;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.mock.web.MockMultipartFile;
//import org.springframework.test.annotation.Rollback;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.util.Collections;
//import java.util.List;
//
//import static com.aliyun.oss.common.utils.CodingUtils.assertTrue;
//import static org.junit.jupiter.api.Assertions.*;
//import static org.mockito.ArgumentMatchers.any;
//import static org.mockito.Mockito.when;
//
//@SpringBootTest
//class FsAdminApplicationTests {
//
//    @Autowired
//    private FileService fileService;
//
//    private static final Long MOCK_USER_ID = 999L;
//
//    private MockedStatic<StpUtil> stpUtilMock;
//
//    @BeforeEach
//    void setUp() {
//        // Mock 登录用户ID
//        stpUtilMock = org.mockito.Mockito.mockStatic(StpUtil.class);
//        stpUtilMock.when(StpUtil::getLoginIdAsLong).thenReturn(MOCK_USER_ID);
//    }
//
//    @AfterEach
//    void tearDown() {
//        stpUtilMock.close();
//    }
//
//    @Test
//    @Transactional
//    @Rollback
//    void testAddFolder() {
//        FileInfo folder = new FileInfo();
//        folder.setName("测试文件夹");
//        folder.setDirIds("/");
//
//        boolean result = fileService.addFolder(folder);
//        assertTrue(result, "添加文件夹失败");
//
//        // 再次尝试添加同名文件夹，应抛出异常
//        BusinessException ex = assertThrows(BusinessException.class, () -> fileService.addFolder(folder));
////      assertTrue(ex.getMessage().contains("当前目录名称已存在"));
//    }
//
//    @Test
//    @Transactional
//    @Rollback
//    void testUpdateFileName() {
//        FileInfo file = new FileInfo();
//        file.setName("old-name");
//        file.setDirIds("/");
//        file.setParentId(CommonConstant.ROOT_PARENT_ID);
//        file.setIsDir(false);
//        file.setUserId(MOCK_USER_ID);
//        fileService.save(file);
//
//        UpdateFileNameDTO dto = new UpdateFileNameDTO();
//        dto.setId(file.getId());
//        dto.setName("old-name");
//        dto.setRename("new-name");
//
//        boolean updated = fileService.updateByName(dto);
//        assertTrue(updated, "重命名失败");
//
//        // 再次重命名为相同名称应抛出异常
//        dto.setRename("new-name");
//        BusinessException ex = assertThrows(BusinessException.class, () -> fileService.updateByName(dto));
//        assertEquals("当前名称与原始名称相同，请修改后重试！", ex.getMessage());
//    }
//
//    @Test
//    @Transactional
//    @Rollback
//    void testGetList() {
//        FileInfo info = new FileInfo();
//        info.setName("列表测试文件");
//        info.setIsDir(false);
//        info.setParentId(CommonConstant.ROOT_PARENT_ID);
//        info.setUserId(MOCK_USER_ID);
//        info.setDirIds("/");
//        fileService.save(info);
//
//        List<FileInfo> list = fileService.getList(info);
//        assertFalse(list.isEmpty(), "文件列表不应为空");
//    }
//
////    @Test
////    @Transactional
////    @Rollback
////    void testUpload() {
////        MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "hello".getBytes());
////
////        Result<?> result = fileService.upload(new MockMultipartFile[]{file}, "/");
////        Result.error("添加失败");
////    }
//
//    @Test
//    @Transactional
//    @Rollback
//    void testUpload() {
//        MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "hello".getBytes());
//
//        Result<?> result = fileService.upload(new MockMultipartFile[]{file}, "/");
//
//        // 断言上传结果
//        assertNotNull(result, "上传结果不能为空");
//        assertEquals(200, result.getCode(), "上传失败，返回的 code 非 200");
//        assertEquals("上传成功", result.getMsg(), "上传失败，msg 不为 '上传成功'");
//        assertNotNull(result.getData(), "上传成功但返回的数据为空");
//    }
//}
